package com.fr.report.parameter;

import com.fr.base.XMLable;
import com.fr.base.xml.XMLObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.parameter.processor.AbstractUnitProcessor;
import com.fr.report.parameter.processor.UnitProcessor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class CustomParameterProcessor extends AbstractParameterProcessor
  implements XMLable
{
  private Map unitProcessorMap = new HashMap();

  public Map process(Map paramMap)
  {
    Map localMap = super.process(paramMap);
    Iterator localIterator = this.unitProcessorMap.entrySet().iterator();
    while (true)
    {
      String str;
      UnitProcessor localUnitProcessor;
      do
      {
        if (!(localIterator.hasNext()))
          break label94;
        Map.Entry localEntry = (Map.Entry)localIterator.next();
        str = (String)localEntry.getKey();
        localUnitProcessor = (UnitProcessor)this.unitProcessorMap.get(str);
      }
      while (localUnitProcessor == null);
      localMap.put(str, localUnitProcessor.process(paramMap));
    }
    label94: return localMap;
  }

  public Map getUnitProcessorMap()
  {
    return this.unitProcessorMap;
  }

  public void setUnitProcessorMap(Map paramMap)
  {
    this.unitProcessorMap = paramMap;
  }

  public Parameter[] getParameters()
  {
    Object localObject;
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = this.unitProcessorMap.entrySet().iterator();
    do
    {
      if (!(localIterator.hasNext()))
        break label97;
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      localObject = localEntry.getValue();
    }
    while (!(localObject instanceof AbstractUnitProcessor));
    Parameter[] arrayOfParameter = ((AbstractUnitProcessor)localObject).getParameters();
    int i = 0;
    while (true)
    {
      if (i >= arrayOfParameter.length);
      localArrayList.add(arrayOfParameter[i]);
      ++i;
    }
    label97: return ((Parameter[])localArrayList.toArray(new Parameter[localArrayList.size()]));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("UnitProcessorMap")))
      paramXMLableReader.readXMLObject(new XMLReadable(this)
      {
        private final CustomParameterProcessor this$0;

        public void readXML()
        {
          if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("ParameterUnitProcessor")))
          {
            String str;
            CustomParameterProcessor.2 local2;
            Object localObject = null;
            if ((str = paramXMLableReader.getAttr("parameter")) != null)
              localObject = str;
            paramXMLableReader.readXMLObject(local2 = new CustomParameterProcessor.2(this, null));
            if (localObject != null)
              CustomParameterProcessor.access$000(this.this$0).put(localObject, (UnitProcessor)local2.getObject());
          }
        }
      });
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if ((this.unitProcessorMap != null) && (this.unitProcessorMap.size() > 0))
    {
      paramXMLPrintWriter.startTAG("UnitProcessorMap");
      Iterator localIterator = this.unitProcessorMap.entrySet().iterator();
      while (true)
      {
        String str;
        UnitProcessor localUnitProcessor;
        do
        {
          if (!(localIterator.hasNext()))
            break label120;
          Map.Entry localEntry = (Map.Entry)localIterator.next();
          str = (String)localEntry.getKey();
          localUnitProcessor = (UnitProcessor)this.unitProcessorMap.get(str);
        }
        while (localUnitProcessor == null);
        paramXMLPrintWriter.startTAG("ParameterUnitProcessor").attr("parameter", str);
        ReportXMLUtils.writeUnitProcessor(paramXMLPrintWriter, localUnitProcessor);
        paramXMLPrintWriter.end();
      }
      label120: paramXMLPrintWriter.end();
    }
  }

  static Map access$000(CustomParameterProcessor paramCustomParameterProcessor)
  {
    return paramCustomParameterProcessor.unitProcessorMap;
  }
}